package cn.restcloud.example.controller;

import org.bson.Document;

import cn.restcloud.framework.client.RestClient;
import cn.restcloud.framework.core.annotation.bean.BeanConfig;
import cn.restcloud.framework.core.annotation.bean.BeanType;
import cn.restcloud.framework.core.annotation.rest.MethodType;
import cn.restcloud.framework.core.annotation.rest.RestConfig;
import cn.restcloud.framework.view.base.DocAndView;
import cn.restcloud.framework.view.util.ViewUtil;

/**
 * 调用内部或外部Rest服务示例代码
 * @author Thinkpad
 *
 */
@BeanConfig(appId = "example",beanId = "RestClientDemo",beanName = "RestClient开发测试",beanType = BeanType.CONTROLLER)
@RestConfig(url = "/rest/example/client")
public class RestClientDemo {

	
	@RestConfig(configName = "RestClient测试",method = MethodType.GET,url = "/test")
	public DocAndView testRestClient() throws Exception{
		String url="/rest/example/server/info";
		RestClient rc=RestClient.getInstance().setLoadBlanceBeanId("WeightRandomStrategy").setServiceName("bpm").setConntionTimeOut(6000).setUrl(url);
		Document doc=rc.get().getDocument();
		return ViewUtil.getJsonView(doc);
	}
	
	
	@RestConfig(configName = "RestClient测试",method = MethodType.POST,url = "/getipinfo")
	public DocAndView testPostRestClient() throws Exception{
		String url="http://ip.ws.126.net/ipquery";
		RestClient rc=RestClient.getInstance().setConntionTimeOut(10000).addUrlParams("ip","113.66.218.180").setUrl(url);
		String body=rc.get().getResponseBody();
		return ViewUtil.getJsonView(body);
	}
	
}
